@extends('home.layouts._center')
@push('js')
    <script type="text/javascript" src="{{asset('org/home/js')}}/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="{{asset('org/home/js')}}/jquery.reveal.js"></script>

    <script type="text/javascript" src="{{asset('org/home/js')}}/chengs/jquery.js"></script>
    <script type="text/javascript" src="{{asset('org/home/js')}}/chengs/bootstrap.js"></script>
    <script type="text/javascript" src="{{asset('org/home/js')}}/chengs/city-picker.data.js"></script>
    <script type="text/javascript" src="{{asset('org/home/js')}}/chengs/city-picker.js"></script>
    <script type="text/javascript" src="{{asset('org/home/js')}}/chengs/main.js"></script>
    <script>
        function del(obj) {
            swal({
                title: '确定删除吗？',
                text: '你将无法恢复它！',
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: 'red',
                confirmButtonText: '确定删除！',
            }).then(function (res) {
                // 判断获取的回调是否为真,如果为真,执行删除动作
                if (res) {
                    $(obj).next('form').submit();
                }
            })
        }
    </script>
@endpush
@section('content')
    <div class="mod_main">
        <div class="jib_xinx_kuang">
            <div class="shand_piaot">收货地址</div>
            <div class="shouh_diz_beij">
                @foreach($addresses as $address)
                <div class="shouh_diz_kuang">
                    <div class="item">
                        <span class="labal">收件人：</span>
                        <p>{{$address['linkname']}}</p>
                    </div>
                    <div class="item">
                        <span class="labal">所在地区：</span>
                        <p>{{$address['area']}}</p>
                    </div>
                    <div class="item">
                        <span class="labal">地址：</span>
                        <p>{{$address['address']}}</p>
                    </div>
                    <div class="item">
                        <span class="labal">手机：</span>
                        <p>{{$address['phone']}}</p>
                    </div>
                    <div class="bianj_yv_shanc">
                        @if($address['is_default'])
                            <span class="mor_color">当前默认地址</span>
                        @else
                           <a href="{{route('home.setDefault',$address)}}">设为默认</a>
                        @endif
                        <a href="javascript:;"  data-reveal-id="myModal_{{$address['id']}}">编辑</a>
                        <a href="javascript:;" onclick="del(this)">删除</a>
                            <form action="{{route('home.address.destroy',$address)}}" method="post">
                                @csrf @method('DELETE')
                            </form>
                    </div>
                </div>
                {{--编辑地址表单--}}
                    <form action="{{route('home.address.update',$address)}}" method="post">
                        @csrf @method('PUT')
                        <div id="myModal_{{$address['id']}}" class="reveal-modal">
                            <div class="xint_biaot">
                                <h3>新添收货地址</h3>
                            </div>
                            <div class="shouj_diz_b">
                                <div class="biaod_1">
                                    <p><em>*</em>联系人：</p>
                                    <input type="text" class="text" name="linkname" value="{{$address['linkname']}}">
                                </div>
                                <div class="biaod_1">
                                    <p><em>*</em>收货地址：</p>
                                    <div class="xinz_diz_cs">
                                        <div class="docs-methods">
                                            <form class="form-inline">
                                                <div id="distpicker">
                                                    <div class="form-group">
                                                        <div style="position: relative;">
                                                            <input id="city-picker3" class="form-control" readonly type="text" value="{{$address['area']}}" data-toggle="city-picker" name="area" >
                                                        </div>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                                <div class="biaod_1">
                                    <p><em>*</em>详细地址：</p>
                                    <input type="text" class="text text1" name="address" value="{{$address['address']}}">
                                </div>
                                <div class="biaod_1 biaod_2">
                                    <div class="liangp_e">
                                        <p><em>*</em>手机号码：</p>
                                        <input type="text" class="text" name="phone" value="{{$address['phone']}}">
                                    </div>
                                </div>
                                <div class="biaod_1">
                                    <p><em></em>是否为默认地址：</p>
                                    <select name="is_default">
                                        <option value="1" {{$address['is_default']?'selected':''}}>是</option>
                                        <option value="0" {{$address['is_default']?'':'selected'}}>否</option>
                                    </select>
                                </div>
                                <button type="submit" style="width: 80px;">保存</button>
                            </div>
                            <a class="close-reveal-modal">&#215;</a>
                        </div>
                    </form>
                @endforeach
                <div class="xinz_shouh_dz_ann"><a href="#" data-reveal-id="myModal">新增收货地址</a></div>
            </div>
        </div>
    </div>
    <form action="{{route('home.address.store')}}" method="post">
        @csrf
        <div id="myModal" class="reveal-modal">
            <div class="xint_biaot">
                <h3>新添收货地址</h3>
            </div>
            <div class="shouj_diz_b">
                <div class="biaod_1">
                    <p><em>*</em>联系人：</p>
                    <input type="text" class="text" name="linkname">
                </div>
                <div class="biaod_1">
                    <p><em>*</em>收货地址：</p>
                    <div class="xinz_diz_cs">
                        <div class="docs-methods">
                            <form class="form-inline">
                                <div id="distpicker">
                                    <div class="form-group">
                                        <div style="position: relative;">
                                            <input id="city-picker3" class="form-control" readonly type="text" value="" data-toggle="city-picker" name="area">
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="biaod_1">
                    <p><em>*</em>详细地址：</p>
                    <input type="text" class="text text1" name="address">
                </div>
                <div class="biaod_1 biaod_2">
                    <div class="liangp_e">
                        <p><em>*</em>手机号码：</p>
                        <input type="text" class="text" name="phone">
                    </div>
                </div>
                <div class="biaod_1">
                    <p><em></em>默认地址：</p>
                    <select name="is_default">
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>
                    <button type="submit" style="width: 80px;">保存</button>
            </div>
            <a class="close-reveal-modal">&#215;</a>
        </div>
    </form>
@endsection
